<template>
  <div class="login">
    <img src="@/assets/bg.jpg" alt="">
    <el-container class="container" >
      <el-main>
        <el-form :model="myform" label-width="100px" class="form">
          <el-form-item label="用户">
            <el-input v-model="myform.name"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="myform.pwd" type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button class="btn" type="primary" @click="fudebounce"
              >提交</el-button
            >
          </el-form-item>
        </el-form>
        <el-footer>
          <p>登录注册</p>
          <p><span> | </span>忘记密码 </p>
        </el-footer>
      </el-main>
    </el-container>
  </div>
</template>

<script>

import instance from "../api";
import debounce from "../plugin/debounce.js";
export default {
  name: "Logino",
  data() {
    return {
      myform: {
        name: "ytt",
        pwd: 1314,
      },
    };
  },
  created() {
    this.fnajax = debounce(this.fnsubmit); //业务防抖封装
  },
  methods: {
    fudebounce() {
      //业务防抖封装函数
      this.fnajax();
    },
    async fnsubmit() {
      //业务函数
      let name = this.myform.name;
      let pwd = this.myform.pwd;
      console.log(name, pwd);
      let { data } = await instance.get("/user", { params: { name, pwd } });
      console.log(data);
      // let token = data[0].token;
      if (data.length > 0) {
        localStorage.setItem("token", "token");
        this.$message({
          showClose: true,
          message: "登陆成功",
          type: "success",
          duration: 1000,
          onClose: () => {
            this.$router.push({ name: "Home" });
          },
        });
      }
    },
  },
};
</script>

<style scoped>
.login{
  width: 100%;
  height: 680px;
  position: relative;
}
.login img{
width: 100%;
height: 100%;
}
.container{
   width: 1100px;
   position: absolute;
   top: 0;
   left: 0;
}
.el-main{
  width: 600px;
  height: 400px;
  background: rgba(255, 255, 255, .4);
  padding-top: 100px;
  margin: 200px 0 0 500px;
}
.el-main .el-form-item{
    width: 500px;
}
.btn{
    width: 400px;
}
.el-footer{
  display: flex;
justify-content: center;
}
.el-footer p{
  line-height: 60px;
  /* margin-right: 25px; */
  color: #fff;
}
.el-footer p span{
  color: #47b8e7;
  margin:0 3px 0 5px;
}
</style>